<script setup>
import { inject, computed } from 'vue'

// 注入数据
const infoData = inject('infoData', [])
const loading = inject('loading', true)

// 过滤出标题为"基本情况"的信息
const basicInfos = computed(() => {
  return infoData.value.filter(info => info.title === '基本情况')
    .sort((a, b) => a.displayOrder - b.displayOrder)
})
</script>

<template>
  <div class="basic-info-container">
    <h1 class="section-title">基本情况</h1>
    
    <div v-if="loading" class="loading-container">
      <el-skeleton :rows="5" animated />
    </div>
    
    <div v-else-if="basicInfos.length === 0" class="empty-state">
      <p>暂无基本情况数据</p>
    </div>
    
    <div v-else class="info-content">
      <div v-for="info in basicInfos" :key="info.id" class="info-item">
        <div class="info-description" v-html="formatDescription(info.description)"></div>
      </div>
    </div>
  </div>
</template>

<script>
// 格式化描述文本，将换行符转换为 <br> 标签
function formatDescription(text) {
  if (!text) return ''
  return text.replace(/\n/g, '<br>')
}
</script>

<style scoped>
.basic-info-container {
  padding: 2rem;
  background-color: #fff;
  border-radius: 8px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.05);
}

.section-title {
  font-size: 1.8rem;
  color: #333;
  margin-bottom: 1.5rem;
  padding-bottom: 0.8rem;
  border-bottom: 2px solid #eaeaea;
  position: relative;
}

.section-title::after {
  content: '';
  position: absolute;
  bottom: -2px;
  left: 0;
  width: 80px;
  height: 2px;
  background-color: #409EFF;
}

.loading-container {
  padding: 1rem 0;
}

.empty-state {
  text-align: center;
  padding: 3rem;
  color: #909399;
  font-size: 1.2rem;
}

.info-content {
  margin-top: 1.5rem;
}

.info-item {
  margin-bottom: 1.5rem;
  padding-bottom: 1.5rem;
  border-bottom: 1px dashed #eaeaea;
}

.info-item:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.info-description {
  font-size: 1rem;
  line-height: 1.8;
  color: #606266;
  text-align: justify;
}

/* 响应式设计 */
@media (max-width: 768px) {
  .basic-info-container {
    padding: 1.5rem;
  }
  
  .section-title {
    font-size: 1.5rem;
  }
}

@media (max-width: 480px) {
  .basic-info-container {
    padding: 1rem;
  }
  
  .section-title {
    font-size: 1.3rem;
  }
  
  .info-description {
    font-size: 0.9rem;
  }
}
</style>